{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "43ffb51d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f9f9f28b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                                 source  target\n",
      "0                                Mashup: #API Christmas       1\n",
      "1           Mashup: #Ask4Stuff: WorldCat Twitter Search       2\n",
      "2     Mashup: #BeerMap - The Top 2,500 Beers on Twitter       3\n",
      "3     Mashup: #LinS Stats on Your LinkedIn Social Graph       2\n",
      "4                                        Mashup: #S42AT       4\n",
      "...                                                 ...     ...\n",
      "6066                    Mashup: youbeQ - Maps with Life       5\n",
      "6067                                Mashup: youniversus       1\n",
      "6068                                Mashup: youwerecute       1\n",
      "6069                               Mashup: ytwebservice       1\n",
      "6070                                     Mashup: zangoa       1\n",
      "\n",
      "[6071 rows x 2 columns]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\l\\AppData\\Local\\Temp\\ipykernel_79592\\305928480.py:4: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.\n",
      "\n",
      "\n",
      "  data_edges=pd.read_csv(m_a_edges, encoding=\"utf-8\",sep='\\t', error_bad_lines=False)\n"
     ]
    }
   ],
   "source": [
    "# 1\n",
    "# 1.1 每个Mashup包含的Web API个数\n",
    "m_a_edges=\"m-a_edges.csv\"\n",
    "data_edges=pd.read_csv(m_a_edges, encoding=\"utf-8\",sep='\\t', error_bad_lines=False)\n",
    "mashup_invoke_api=data_edges.groupby(\"source\").count().reset_index()\n",
    "print(mashup_invoke_api)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "07c56d6f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   target  source\n",
      "0       /api/123-shop-pro       1\n",
      "1     /api/123contactform       1\n",
      "2        /api/12secondstv       1\n",
      "3          /api/140-proof       1\n",
      "4            /api/18amail       1\n",
      "...                   ...     ...\n",
      "1503          /api/zooomr       4\n",
      "1504          /api/zoopla       2\n",
      "1505         /api/zootool       1\n",
      "1506          /api/zotero       2\n",
      "1507          /api/zvents       7\n",
      "\n",
      "[1508 rows x 2 columns]\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\l\\AppData\\Local\\Temp\\ipykernel_79592\\531557172.py:1: FutureWarning: The error_bad_lines argument has been deprecated and will be removed in a future version. Use on_bad_lines in the future.\n",
      "\n",
      "\n",
      "  data_edges=pd.read_csv(m_a_edges, encoding=\"utf-8\",sep='\\t', error_bad_lines=False)\n"
     ]
    }
   ],
   "source": [
    "data_edges=pd.read_csv(m_a_edges, encoding=\"utf-8\",sep='\\t', error_bad_lines=False)\n",
    "api_usetimes=data_edges.groupby(\"target\").count().reset_index()\n",
    "print(api_usetimes)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ec649129",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('https://api.nasa.gov/', 24)\n",
      "('http://www.sentisum.com/apis.html', 17)\n",
      "('https://zenhub.zengenti.com/Contensis/11.3/development/Contensis-developer.aspx', 16)\n",
      "('https://www.cricketapi.com/', 15)\n",
      "('http://docs.polysync.io/', 13)\n",
      "('http://developer.tipsgo.com/', 13)\n",
      "('https://www.cmtelecom.com/', 13)\n",
      "('https://developer.avios.com/', 12)\n",
      "('https://www.dbs.com/dbsdevelopers/discover/index.html', 12)\n",
      "('http://domainconnect.org/wp-content/uploads/2016/08/Domain-Connect-Spec-Draft-v17-1.pdf', 12)\n"
     ]
    }
   ],
   "source": [
    "import json\n",
    "file1 = open('api_version_accessbiliby-1.txt', 'r')\n",
    "js1 = file1.read()\n",
    "ava1 = json.loads(js1)\n",
    "# print(ava1)\n",
    "\n",
    "file2 = open('api_version_accessbiliby-2.txt', 'r')\n",
    "js2 = file2.read()\n",
    "ava2 = json.loads(js2)\n",
    "\n",
    "file3 = open('api_version_accessbiliby-3.txt', 'r')\n",
    "js3 = file3.read()\n",
    "ava3 = json.loads(js3)\n",
    "\n",
    "file4 = open('api_version_accessbiliby-4.txt', 'r')\n",
    "js4 = file4.read()\n",
    "ava4 = json.loads(js4)\n",
    "\n",
    "file5 = open('api_version_accessbiliby-5.txt', 'r')\n",
    "js5 = file5.read()\n",
    "ava5 = json.loads(js5)\n",
    "file5.close()\n",
    "\n",
    "# print(ava1[0])\n",
    "# print(ava1[1])\n",
    "res={}\n",
    "count=0\n",
    "\n",
    "#ava1\n",
    "for i in range(len(ava1)):\n",
    "    api_info=ava1[i]['visit_status']\n",
    "    for j in range(len(api_info)):\n",
    "        if(api_info[j]['visit_label']=='API Portal / Home Page'):\n",
    "            url=api_info[j]['visit_url']\n",
    "            if(res.get(url,'A')=='A'):\n",
    "                res[url]=1\n",
    "            else:\n",
    "                res[url]+=1\n",
    "\n",
    "#ava2\n",
    "for i in range(len(ava2)):\n",
    "    api_info=ava2[i]['visit_status']\n",
    "    for j in range(len(api_info)):\n",
    "        if(api_info[j]['visit_label']=='API Portal / Home Page'):\n",
    "            url=api_info[j]['visit_url']\n",
    "            if(res.get(url,'A')=='A'):\n",
    "                res[url]=1\n",
    "            else:\n",
    "                res[url]+=1\n",
    "\n",
    "#ava3\n",
    "for i in range(len(ava3)):\n",
    "    api_info=ava3[i]['visit_status']\n",
    "    for j in range(len(api_info)):\n",
    "        if(api_info[j]['visit_label']=='API Portal / Home Page'):\n",
    "            url=api_info[j]['visit_url']\n",
    "            if(res.get(url,'A')=='A'):\n",
    "                res[url]=1\n",
    "            else:\n",
    "                res[url]+=1\n",
    "\n",
    "#ava4\n",
    "for i in range(len(ava4)):\n",
    "    api_info=ava4[i]['visit_status']\n",
    "    for j in range(len(api_info)):\n",
    "        if(api_info[j]['visit_label']=='API Portal / Home Page'):\n",
    "            url=api_info[j]['visit_url']\n",
    "            if(res.get(url,'A')=='A'):\n",
    "                res[url]=1\n",
    "            else:\n",
    "                res[url]+=1\n",
    "\n",
    "#ava5\n",
    "for i in range(len(ava5)):\n",
    "    api_info=ava5[i]['visit_status']\n",
    "    for j in range(len(api_info)):\n",
    "        if(api_info[j]['visit_label']=='API Portal / Home Page'):\n",
    "            url=api_info[j]['visit_url']\n",
    "            if(res.get(url,'A')=='A'):\n",
    "                res[url]=1\n",
    "            else:\n",
    "                res[url]+=1\n",
    "\n",
    "# print(count)\n",
    "\n",
    "new_res=sorted(res.items(),key=lambda item:-item[1])\n",
    "\n",
    "for i in range(10):\n",
    "    print(new_res[i])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "071290f7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
